<template>
  <view class="cabinet">
    <!-- <nut-watermark :z-index="999" content="小刘"></nut-watermark> -->
    <scroll-view 
        style="height: 100%;"
        :scroll-y="true"
        :refresherEnabled="true"
        :refresherTriggered="isFresh"
        @refresherRefresh="refresherRefresh"
      >
      <view v-if="cabinetData.length" class="cabinetItem" v-for="item in cabinetData" :key="item.c_code" @tap="gotoPage(item)">
        <view class="title">
          <view class="title_s">{{ item.c_cabinet_name }}</view>
          <view>
            <nut-tag type="success" v-if="item.c_activate == 1"> 在线 </nut-tag>
            <nut-tag type="danger" v-else> 离线 </nut-tag>
          </view>
        </view>
        <view class="content">
          <view class="c_item">设备组数： {{ item.c_cabinet_num }}</view>
          <view class="c_item">眼镜层数： {{ item.c_glasses_layer }}</view>
          <view class="c_item">每层组数： {{ item.c_layer_group }}</view>
          <view class="c_item">每层数量： {{ item.c_group_glasses_num }}</view>
        </view>
        <nut-divider v-if="!!item.result_data.key1" dashed :style="{padding: '0 5px', margin: '5px 0px'}"> 设备剩余数量 </nut-divider>
        <view class="content" v-if="!!item.result_data.key1">
          <view class="c_item">成人款： {{ item.result_data.key1.cr }}</view>
          <view class="c_item">儿童款： {{ item.result_data.key1.et }}</view>
          <view class="c_item">挂夹款： {{ item.result_data.key1.gj }}</view>
        </view>
      </view>
      <view v-else>
      <nut-empty description="暂无数据"></nut-empty>
    </view>
    </scroll-view>
  </view>
</template>

<script setup>
import './index.scss';
import { ref } from 'vue';
import {equipmentList} from '../../https/api'
import Taro from '@tarojs/taro';

const isFresh = ref(false)
const cabinetData = ref([])

const gotoPage = (item) => {
  Taro.navigateTo({
    url: `/pages/cabinetDetail/index?data=${JSON.stringify(item)}`
  })
}
const getList = () => {
  equipmentList().then(res => {
    if(res.code == '1000') {
      isFresh.value = false
      cabinetData.value = res.data
    } else {
      isFresh.value = false
    }
  })
}
const refresherRefresh = () => {
  isFresh.value = true
  getList()
}
getList()
</script>

<style>
</style>